package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "job_", schema = "crm")
public class Job {
    private int jobId;
    private String jobName;
    private Department department;
    private List<Function> funs;
    private List<Employee> emps;
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "function_job_",
            joinColumns = {
                    @JoinColumn(name = "job_id")
            },
            inverseJoinColumns = {
                    @JoinColumn(name = "function_id")
            })
    public List<Function> getFuns() {
        return funs;
    }

    public void setFuns(List<Function> funs) {
        this.funs = funs;
    }

    @Id
    @Column(name = "job_id", nullable = false)
    public int getJobId() {
        return jobId;
    }

    public void setJobId(int jobId) {
        this.jobId = jobId;
    }

    @Basic
    @Column(name = "job_name", nullable = true, length = 255)
    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Job job = (Job) o;
        return jobId == job.jobId &&
                Objects.equals(jobName, job.jobName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(jobId, jobName);
    }


    @ManyToOne
    @JoinColumn(name = "dept_id", referencedColumnName = "dept_id")
    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    @OneToMany(mappedBy = "job",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    public List<Employee> getEmps() {
        return emps;
    }

    public void setEmps(List<Employee> emps) {
        this.emps = emps;
    }
}
